<?php echo $header; ?>
<div class="alert-wrap">
    <div class="alert-test alert-position"></div>
</div>
<div class="container in-wrap">
    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <h1 class="text-center"><?php echo $maincontent; ?></h1>
            <div class="center-wrap">
                <div class="center-inner">
                    <a href="javascript:void(0);" class="btn btn-primary" id="load-data">加载本页数据</a>
                   <!--  <a href="javascript:void(0);" class="btn btn-primary" id="add-data">添加采集知识点</a>
                    <a href="javascript:void(0);" class="btn btn-primary" id="delete-data">删除所有知识点</a> -->
                </div>
            </div>
        </div>
    </div>
</div>
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <h4 class="text-center test-info">
            <table class="table table-bordered table-hover table-test">
                <tr class="test-tr-header">
                </tr>
            </table>
          </h4>
            <p class="text-center">
                <?php echo $contents; ?>
            </p>
        </div>
    </div>
    <div class="nav" aria-label="Page navigation">
        <div class="center-wrap">
            <div class="center-inner">
                <?php echo $pagination; ?>
            </div>
        </div>
    </div>
</div>
<?php echo $footerin;?>
<script>
$(function() {
    var $target = $('.test-info');
    var $alerttarget = $('.alert-test');
    var idinfo;
    var imgs;
    $("#load-data").click(function() {
        $(".test-tr-header").html("");
        $(".table-test tr:gt(0)").remove();
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "<?php echo $selfurl; ?>",
            beforeSend: function() {
                idinfo = '正在查询数据请稍后……';
                alertjts($alerttarget, idinfo);
            },
            success: function(data) {
                var info;
                var vone;
                var tabledata = "<tr>";
                /*if (data.length>1){
                  $.each(data[0],function(index,value){
                    vone ="<th>"+index+"</th>";
                        $(".test-tr-header").append(vone);
                  })
                  $.each(data,function(i,v){
                    $.each(v,function(ind,val){
                      tabledata +="<td>"+val+"</td>";
                    })
                    tabledata +="</tr>";
                  })
                  $(".test-tr-header").after(tabledata);
                  alertjts($alerttarget,"共"+data.length+"条");
                }else{*/
                var temp = JSON.stringify(data);
                $target.html(temp);
                if(data){
                    alertjts($alerttarget, "共" + data.length + "条");
                }else{
                    alertjts($alerttarget, "data is false");
                }
                
                // }

            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                var xmlr = XMLHttpRequest.status;
                var xmlrday = XMLHttpRequest.readyState;
                var xmlres = XMLHttpRequest.responseText;
                var texts = textStatus;
                var errt = errorThrown;
                if (xmlr) {
                    $target.append("XMLHttpRequest.status:<br>" + xmlr + "<br>");
                }
                if (xmlrday) {
                    $target.append("XMLHttpRequest.readyState:<br>" + xmlrday + "<br>");
                }
                if (xmlres) {
                    $target.append("XMLHttpRequest.responseText:<br>" + xmlres + "<br>");
                }
                if (texts) {
                    $target.append("textStatus:<br>" + texts + "<br>");
                }
                if (errt) {
                    $target.append("errorThrown:<br>" + errt + "<br>");
                }
            },
            complate: function(data) {
                var temp = JSON.stringify(data);
                $target.html(temp);
            }
        })
    })

    $("#add-data").on("click", function() {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "<?php echo $addurl; ?>",
            beforeSend: function() {
                idinfo = "正在查询数据请稍后……";
                $target.html(idinfo).fadeIn();
            },
            success: function(data) {
                var temp = JSON.stringify(data);
                $target.html(temp);
            }
        })
    })
    $('#delete-data').on("click", function() {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "<?php echo $delurl; ?>",
            beforeSend: function() {
                idinfo = "正在查询数据请稍后……";
                $target.html(idinfo).fadeIn();
            },
            success: function(data) {
                var temp = JSON.stringify(data);
                $target.html(temp);
            }
        })
    })
})
</script>
<?php echo $footer;?>
